<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="/tracing/model/event_set.html">
<link rel="import" href="/tracing/ui/analysis/analysis_sub_view.html">
<link rel="import" href="/tracing/ui/analysis/multi_event_sub_view.html">

<script>
'use strict';

Polymer({
  is: 'tr-ui-a-multi-frame-sub-view',
  behaviors: [tr.ui.analysis.AnalysisSubView],

  created() {
    this.currentSelection_ = undefined;
  },

  set selection(selection) {
    Polymer.dom(this).textContent = '';
    const realView = document.createElement('tr-ui-a-multi-event-sub-view');
    realView.eventsHaveDuration = false;
    realView.eventsHaveSubRows = false;

    Polymer.dom(this).appendChild(realView);
    realView.setSelectionWithoutErrorChecks(selection);

    this.currentSelection_ = selection;
  },

  get selection() {
    return this.currentSelection_;
  },

  get relatedEventsToHighlight() {
    if (!this.currentSelection_) return undefined;

    const selection = new tr.model.EventSet();
    this.currentSelection_.forEach(function(frameEvent) {
      frameEvent.associatedEvents.forEach(function(event) {
        selection.push(event);
      });
    });
    return selection;
  }
});
tr.ui.analysis.AnalysisSubView.register(
    'tr-ui-a-multi-frame-sub-view',
    tr.model.Frame,
    {
      multi: true,
      title: 'Frames',
    });
</script>
